package com.flower.wholesale.service.impl;

import com.flower.wholesale.entity.Manager;
import com.flower.wholesale.enu.StatausEnum;
import com.flower.wholesale.mapper.ManagerMapper;
import com.flower.wholesale.service.ManagerService;
import com.flower.wholesale.util.MD5Util;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 后台管理员账号表 服务实现类
 * </p>
 *
 * @author 姚雁飞
 * @since 2020-01-17
 */
@Service
public class ManagerServiceImpl extends ServiceImpl<ManagerMapper, Manager> implements ManagerService {

	@Override
	public JSONObject login(String loginName, String password, String code) {
		JSONObject result = new JSONObject();
		result.put("code", StatausEnum.Error.getCode());
		result.put("msg", "用户名或密码不对");
		QueryWrapper<Manager> qw = new QueryWrapper<Manager>();
		qw.eq("login_name", loginName);
		Manager m = this.getOne(qw);
		if (StringUtils.isNotEmpty(m.getPassword())) {
			String newPassword = m.getPassword() + MD5Util.getMd5(code);
			newPassword = MD5Util.getMd5(newPassword);
			if (password.equals(newPassword)) {
				result.put("code", StatausEnum.SUCCESS.getCode());
				result.put("msg", "登录成功");
				result.put("data",m);
			}
		}
		return result;
	}

}
